package com.ssy.lingxi.message.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.vo.request.MessageIdRequest;
import com.ssy.lingxi.message.api.vo.request.SendPlatformMessageRequest;
import com.ssy.lingxi.message.api.vo.response.MessageResponse;
import com.ssy.lingxi.message.service.IMainMessageService;
import com.ssy.lingxi.message.service.IMemberMessageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @menu 平台后台-消息管理
 * @author yzc
 * @version 2.0.0
 * @date 2020/10/27
 */
@RestController
@RequestMapping("/message/message/platform")
public class PlatformMessageController extends BaseController {

    @Resource
    private IMemberMessageService memberMessageService;
    @Resource
    private IMainMessageService mainMessageService;

    /**
     * 平台后台-消息管理-历史消息分页列表
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/page")
    Wrapper<PageData<MessageResponse>> pagePlatformMessage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return memberMessageService.pagePlatformMessage(request, loginUser);
    }

    /**
     * 平台后台-消息中心-设置已读消息
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping("/read")
    Wrapper<Void> updateReadMemberMessage(@Validated @RequestBody MessageIdRequest request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return memberMessageService.updateReadPlatformMessage(request,loginUser);
    }

    /**
     * 平台后台-消息中心-设置全部已读消息
     * @return 返回结果
     */
    @PostMapping("/readAll")
    Wrapper<Void> updateAllReadMemberMessage() {
        UserLoginCacheDTO loginUser = getSysUser();
        return memberMessageService.updateAllReadPlatformMessage(loginUser);
    }

    /**
     * 平台后台-消息管理-消息发送
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping("/send")
    Wrapper<Void> sendPlatformMessage(@RequestBody @Validated SendPlatformMessageRequest request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return mainMessageService.sendPlatformMessage(request, loginUser);
    }
}
